import os, sys
# sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
import onnxmodel.onnx_if as inf
import cv2
import numpy as np

vis_thres=0.6

image_path = "./feature_num_err_all/"
imwrite_path="./feature_num_err_all_result/"

imgs = os.listdir(image_path)
for img in imgs[14:]:
    rename=img.split(".jpg")[0]+"_.jpg"
    img_raw = cv2.imread(image_path + img, cv2.IMREAD_COLOR)
    res = inf.onnx_inference(img_raw)

    # show image
    for b in res:
        if b[4] < vis_thres:
            continue
        text = "{:.4f}".format(b[4])
        b = list(map(int, b))
        cv2.rectangle(img_raw, (b[0], b[1]), (b[2], b[3]), (0, 0, 255), 2)

        cx = b[0]
        cy = b[1] + 12
        cv2.putText(img_raw, text, (cx, cy),
                    cv2.FONT_HERSHEY_DUPLEX, 0.5, (255, 255, 255))

        # img_raw2 =img_raw.copy()

        # landms

        cv2.circle(img_raw, (b[5], b[6]), 1, (0, 0, 255), 4)  # Left eye left corner
        cv2.circle(img_raw, (b[7], b[8]), 1, (0, 255, 255), 4)  # Right eye right corner
        cv2.circle(img_raw, (b[9], b[10]), 1, (255, 0, 255), 4)  # Nose tip
        cv2.circle(img_raw, (b[11], b[12]), 1, (0, 255, 0), 4)  # Left Mouth corner
        cv2.circle(img_raw, (b[13], b[14]), 1, (255, 0, 0), 4)  # Right mouth corner

        # # show pose_estimation
        # size = img_raw.shape[:2]
        # image_points=np.float32([
        #     [b[9], b[10]],  # Nose tip
        #     [b[9], b[10]],  # Chin
        #     [b[5], b[6]],  # Left eye left corner
        #     [b[7], b[8]],  # Right eye right corner
        #     [b[11], b[12]],  # Left Mouth corner
        #     [b[13], b[14]]  # Right mouth corner
        # ])
        #
        # ret, rotation_vector, translation_vector, camera_matrix, dist_coeffs, (pitch, yaw, roll) = inf.get_pose_estimation(
        #     size, image_points)
        # cv2.putText(img_raw, '%.2f' % pitch + ',' + '%.2f' % yaw + ',' + '%.2f' % roll, (0, 120), cv2.FONT_HERSHEY_PLAIN, 1,
        #             (0, 0, 255), 1)
        #
        #
        #
        # #####################################################
        # image_points = np.float32([
        #     [313, 195],
        #     [313, 195],
        #     [294, 174],
        #     [330, 175],
        #     [298, 214],
        #     [324, 215]
        # ])
        # print(image_points)
        #
        # # landms
        # cv2.circle(img_raw2, (294, 174), 1, (0, 0, 255), 4)  # Left eye left corner
        # cv2.circle(img_raw2, (330, 175), 1, (0, 255, 255), 4)  # Right eye right corner
        # cv2.circle(img_raw2, (313, 195), 1, (255, 0, 255), 4)  # Nose tip
        # cv2.circle(img_raw2, (298, 214), 1, (0, 255, 0), 4)  # Left Mouth corner
        # cv2.circle(img_raw2, (324, 215), 1, (255, 0, 0), 4)  # Right mouth corner
        # ret, rotation_vector, translation_vector, camera_matrix, dist_coeffs, (
        # pitch, yaw, roll) = inf.get_pose_estimation(
        #     size, image_points)
        # cv2.putText(img_raw2, '%.2f' % pitch + ',' + '%.2f' % yaw + ',' + '%.2f' % roll, (0, 120),
        #             cv2.FONT_HERSHEY_PLAIN, 1,
        #             (0, 0, 255), 1)


    cv2.imshow(img, img_raw)
    # cv2.imshow(img+"2", img_raw2)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    # cv2.imwrite(imwrite_path+rename,res)

'''
img_raw = cv2.imread(image_path+"1608348300080.jpg", cv2.IMREAD_COLOR)
res=inf.onnx_inference(img_raw)

cv2.imshow("res",res)
cv2.waitKey(0)
'''
